/**
 * related to todoreceipt.ui
 * 
 * @Author : lily80239464
 * @Timestamp : 2017-11-13
 */
var util=require("ui/util");
util.init("do_ALayout_back");
var do_App = sm("do_App");
var do_Page = sm("do_Page");
var do_DataCache = sm("do_DataCache");
var do_Notification = sm("do_Notification");

var listview = ui("do_ListView_1");
ui("do_Label_no_data").visible = false;

var getdata;

var baseUrl = do_DataCache.loadData("baseUrl");
var loginer = do_DataCache.loadData("loginer");
deviceone.print(JSON.stringify(loginer))
var url = "http://125.74.207.139:8010/webservice/a.asmx/" + "GetGDinfoUnFinish?User_id=1";
deviceone.print(url);
refreshAllData();

//刷新数据
function refreshAllData() {
	var http = mm("do_Http");
	http.method = "GET"; // GET | POST
	http.timeout = 30000; // 超时时间 : 单位 毫秒
	http.contentType = "application/x-www-form-urlencoded"; // Content-Type
	http.url = url;// 请求的 URL
	http.on("success", function(data) {
		deviceone.print(JSON.stringify(data));

		var jsonString = data.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">","");
		jsonString = jsonString.replace("</string>","");
		
		var jsondata = JSON.parse(jsonString);
		
		var listdata = jsondata.returnObj;
		
		if (data.length > 0) {
			var listdataTabs = mm("do_ListData");
			getdata = listdata;
			listdataTabs.addData(listdata);
			listview.bindItems(listdataTabs);
			listview.refreshItems({});
		} else {
			ui("do_Label_no_data").visible = true;
		}
		listview.rebound();
	//	loadingUI.visible = false;
	});
	http.on("fail", function(data) {
	//	loadingUI.visible = false;
		listview.rebound();
		do_Notification.toast("网络故障");
	});
	http.request();
}

listview.on("touch", function (data) {
	
	do_DataCache.saveData("current", getdata[data])
	do_App.openPage({
		source: "source://view/todoReceipt/tododetail/tododetail.ui",
		statusBarState: "transparent",
		animationType: "push_r2l",
		data: {detaildata : getdata[data],
				type : "GetGDinfoUnFinish"
		}
	});
	
});

// 下拉刷新
listview.on("pull", function (data) {
	
	refreshAllData();
	
});

